//
//  TZLoadAndRegistVc.m
//  BSBDJ
//
//  Created by user on 16/5/23.
//  Copyright © 2016年 Burning. All rights reserved.
//

#import "TZLoadAndRegistVc.h"
#import "TZLoadRegistView.h"
#import "UMSocial.h"

@interface TZLoadAndRegistVc ()

/** 登陆注册View*/

@property (weak, nonatomic) IBOutlet UIView *content_View;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintLeft;


@end

@implementation TZLoadAndRegistVc



- (IBAction)qqLoad:(UIButton*)sender {
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        //          获取微博用户名、uid、token等
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQQ];
            NSLog(@"\nusername = %@,\n usid = %@,\n token = %@ iconUrl = %@,\n unionId = %@,\n thirdPlatformUserProfile = %@,\n thirdPlatformResponse = %@ \n, message = %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL, snsAccount.unionId, response.thirdPlatformUserProfile, response.thirdPlatformResponse, response.message);
            
        }});
}
- (IBAction)weiboLoad:(UIButton*)sender {
    // 1.创建UMSocialSnsPlatform对象
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    
    // 2.第三方登录
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        // 获取微博用户名、uid、token等
        if (response.responseCode == UMSResponseCodeSuccess) {
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            
        }});
    
    
    [[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"response is %@",response);
    }];
   
}
- (IBAction)tecentLoad:(UIButton*)sender {
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        //          获取微博用户名、uid、token等
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
//            NSDictionary *dict = [UMSocialAccountManager socialAccountDictionary];
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToTencent];
            NSLog(@"\nusername = %@,\n usid = %@,\n token = %@ iconUrl = %@,\n unionId = %@,\n thirdPlatformUserProfile = %@,\n thirdPlatformResponse = %@ \n, message = %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL, snsAccount.unionId, response.thirdPlatformUserProfile, response.thirdPlatformResponse, response.message);
            
        }});
}



- (IBAction)close_Btn:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)switchRegist_Btn:(UIButton*)sender {

    sender.selected = !sender.selected;

    _constraintLeft.constant = _constraintLeft.constant == 0? -TZScreenW : 0;
    [UIView animateWithDuration:0.25 animations:^{
        [self.view layoutIfNeeded];
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
    
}

- (void)setupUI
{
    // 默认一个view从xib加载,尺寸跟xib一样
    TZLoadRegistView *loginView = [TZLoadRegistView switchLoadView];
    [self.content_View addSubview:loginView];
    
    // 添加注册view
    TZLoadRegistView *registerView = [TZLoadRegistView switchRegistView];
    [self.content_View addSubview:registerView];
}


- (void)dealloc{
    NSLog(@"delloc----denglu");
}


- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    // 设置登录
    TZLoadRegistView *loginView = self.content_View.subviews[0];
    loginView.frame = CGRectMake(0, 0, self.content_View.width * 0.5, self.content_View.height);
    
    loginView.centerY = self.content_View.height *0.7;
    
    // 设置注册
    TZLoadRegistView *registerView = self.content_View.subviews[1];
    registerView.frame = CGRectMake(self.content_View.width * 0.5, 0, self.content_View.width * 0.5, self.content_View.height);
registerView.centerY = self.content_View.height *0.7;
    
}


@end
